package jp.oesf.rssreader;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
/*
 * RSS Reader 詳細画面
 * 
 */
import android.widget.TextView;

public class RssReaderDetail extends Activity {

	long id;					
	TextView chammel ;			//　サイト名
	TextView title ;			//　記事タイトル
	TextView description ;		//　本文
	TextView pubDate ;			//　発行日			
	TextView category ;			//　分類
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// R.javaファイルからリソース情報の取得
		setContentView(R.layout.rss_reader_detail);
		title = (TextView)findViewById(R.id.title);
		description = (TextView)findViewById(R.id.description);
		pubDate = (TextView)findViewById(R.id.pubDate);
		category = (TextView)findViewById(R.id.category);		
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

        RssReaderSQLiteOpenHelper databaseOpenHelper = new RssReaderSQLiteOpenHelper(this);
        SQLiteDatabase database = null;

        // 読込専用のSQLiteDatabaseオブジェクトの取得
        database = databaseOpenHelper.getReadableDatabase();

        Cursor chammelcursor = database.query(RssReaderSQLiteOpenHelper.CHANNEL_TABLE, 
        		null, null, null, null, null, null);
        
        if (chammelcursor != null && chammelcursor.getCount() != 0) {
            startManagingCursor(chammelcursor);
            chammelcursor.moveToFirst();
            
            // アプリケーションバーにサイト名を表示
            setTitle(chammelcursor.getString(chammelcursor.getColumnIndex("channel")));
        }
		
		Bundle extras = getIntent().getExtras();
		id  = extras.getLong("id");

		Cursor cursor = database.query(RssReaderSQLiteOpenHelper.ITEM_TABLE, 
				null, "_id="+id, null, null, null, null);
		if (cursor != null) {
			startManagingCursor(cursor);
			cursor.moveToFirst();
			title.setText(cursor.getString(cursor.getColumnIndex("title")));
			description.setText(cursor.getString(cursor.getColumnIndex("description")));
			pubDate.setText(cursor.getString(cursor.getColumnIndex("pubDate")));
			category.setText(cursor.getString(cursor.getColumnIndex("category")));
		}
		databaseOpenHelper.close();
	}
}